if(!dojo._hasResource["market.widgets.component.Tribe"]){
dojo._hasResource["market.widgets.component.Tribe"]=true;
require(["dojo/_base/declare","market/widgets/CommonWidget","dojo/query","dojo/dom","dojo/_base/array"],function(declare,_widget,query,dom,array){
declare("market.widgets.component.Tribe",[_widget],{
_templateHTML:'<div style="padding:5px;"><div class="nickNameHeader1">{label1}</div>'+((participant.isGuest)?'':'<div class="sub_menu_title_right"><a href="#" id="hrefAddTribe">{label2}</a></div>')+'</div><div class="clear"></div>{tribesHTML}',
_tribeHTML:'<div><div class="box_album" name="div_box_album"><div class="box_album_title">{name}</div><div class="box_album_content"><input type="hidden" value="{guid}"/><img alt="" src="getContent/{avatarGUID}/medium" class="box_picture border_thin"/></div></div></div>',
_CREATE_FORM:"tribe.createForm",_createForm:null,_dataSource:{},target:null,
show:function(){
   var w=this;
   var args = {ajaxUrl:'participant/'+participant.guid+'/tribe/list',contentId:this._target(),callback:function(data){
      w._parseTribes(data);
   }};
   SYSTEMWIDGET.ajaxWidget(args).callXhrGetJson();
},
_target:function(){
   if (this.target==null) this.target=dojo.byId('center_content');
   return this.target;
},
_showAddForm:function(){
   this._createForm=this.createForm(this._CREATE_FORM,'center_content','participant/'+participant.id+'/tribe',{},{click:this._handleClickEvents()},null,true);
},
_parseTribes:function(data){
   var w=this;
   this._dataSource=data;
   this._dataSource.tribesHTML=this._parseTribesHTML();
   var templateHTML=dojo.replace(this._templateHTML,this._dataSource);
   dojo.html.set(this._target(),templateHTML,{parseContent: true});
   query('#hrefAddTribe',this.targetNode).onclick(function(){
      w._showAddForm();
   });
   query('div[name="div_box_album"]',this._target()).onclick(function(){
      var tribeGUID=dojo.query('input[type="hidden"]',this)[0].value;
      SYSTEMWIDGET.tribeNews({contentId:w.target,tribeGUID:tribeGUID}).show();
   });
},
_parseTribesHTML:function(){
   var widget=this;
   var tribes=this._dataSource.tribes;
   var templateHTML='';
   array.forEach(tribes,function(tribe,index){
      templateHTML+=dojo.replace(widget._tribeHTML, tribe);
   });
   return templateHTML;
},
_handleClickEvents:function(){
   widget=this;
   var clickEvents = {
      events:['btnCancel','btnAdd'],
      btnCancel:function(data){
         widget.show();
      },
      btnAdd:function(data){
         widget._createForm.callSaveForm({
            handleSuccess:function(data){
               SYSTEMWIDGET.messageWidget().showSucc(data.messageSucc);
               widget.show();
            }
         });}
   };
   return clickEvents;
}
});});}
